from timeit import timeit
import json

from pydantic import TypeAdapter

# from typing_extensions import TypedDict
from typing import TypedDict

import orjson


class ChatConnectGroupMix(TypedDict):
    name: str
    leader: str


class ChatConnectSchemaResp(TypedDict):
    message: str
    group: ChatConnectGroupMix


data = {
    "message": "ok",
    "group": {
        "name": "chenhaifeng1234123412341234144444444444444444444444444444444444444444444444",
        "leader": "chenhaifeng1234sdfsadfsadfuasdioufpoisaudfoipuasdiofuaosiudfoipasudfoiujasdifjklxcjvlkjxcv",
    },
}


data_1 = ChatConnectSchemaResp(message="ok", group=ChatConnectGroupMix(name="chenhaifeng1234123412341234144444444444444444444444444444444444444444444444", leader="chenhaifeng1234sdfsadfsadfuasdioufpoisaudfoip"))
type_chat_conn = TypeAdapter(ChatConnectSchemaResp)

result1 = timeit(lambda: type_chat_conn.dump_json(data_1).decode(), number=10000)

result2 = timeit(lambda: json.dumps(data), number=10000)

result3 = timeit(lambda: orjson.dumps(data), number=10000)

print(result1)
print(result2)
print(result3)
